<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/25 0025
  Time: 上午 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
</head>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>房租水电</cite>
        </a>
      </span>
</div>
<div class="x-body">

    <div class="layui-row">
        <form class="layui-form layui-col-md12" onsubmit="return false">

            <div class="layui-input-inline" style="width: 165px">
                <select name="keyword1" id="keyword1">
                    <c:forEach items="${warehouseList}" var="warehouse">
                        <option value="${warehouse.id}">${warehouse.warehouse_name}</option>
                    </c:forEach>
                </select>
            </div>
            <input type="hidden" id="dateTime">

            <div class="layui-input-inline" style="width: 150px">
                <input class="layui-input" id="date2"  style="width: 150px">
            </div>
            <%--<input type="text" name="keyword2" id="keyword2" placeholder="请输入备注" autocomplete="off" class="layui-input">
            <input type="text" name="keyword3" id="keyword3" placeholder="请输入SAP/QAD" autocomplete="off" class="layui-input">
            <input type="text" name="keyword4" id="keyword4" placeholder="请输入中文名称" autocomplete="off" class="layui-input">--%>
            <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-warm" id="add"><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>
        <button class="layui-btn layui-btn-danger" id="del"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
        <%-- <button class="layui-btn layui-btn-danger" id="import"><i class="layui-icon layui-icon-download-circle"></i>导入</button>
         <button class="layui-btn layui-btn-danger" id="export"><i class="layui-icon layui-icon-upload"></i>导出</button>
         <button class="layui-btn layui-btn-danger" id="dybq"><i class="layui-icon layui-icon-upload-drag"></i>打印标签</button>--%>
    </xblock>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
</div>

<div id="addDivID" style="display:none">
    <form class="layui-form" id="addFormID">
        <xblock>
            <table>
                <tr style="height: 10px"></tr>
                <tr>
                    <td><label class="layui-form-label">时间</label></td>
                    <td>
                        <div class="layui-input-inline" style="width:190px; float: left;">
                            <input class="layui-input" id="date1"  name="parameter3" lay-verify="parameter3">
							<span class="xing" style="margin-left: 101%;"></span>
                        </div>
                    </td>
                    <td><label class="layui-form-label">仓库</label></td>
                    <td>
                        <div class="layui-input-inline" style="width:190px; float: left;">

                            <select  name="warehouse">
                                <c:forEach items="${warehouseList}" var="warehouse">
                                    <option value="${warehouse.id}">${warehouse.warehouse_name}</option>
                                </c:forEach>
                            </select>
                            <span class="xing" style="margin-left: 101%;"></span>
                        </div>
                    </td>
                </tr>
                <tr style="height: 10px"></tr>
                <tr>
                    <td><label class="layui-form-label">供应商</label></td>
                    <td>
                        <div class="layui-input-inline" style="width:190px; float: left;">
                            <select  name="supplier">
                                <c:forEach items="${customerList}" var="customer">
                                    <option value="${customer.id}">${customer.customer_name}</option>
                                </c:forEach>
                            </select>
                            <span class="xing" style="margin-left: 101%;"></span>
                        </div>
                    </td>
                    <td><label class="layui-form-label">名称</label></td>
                    <td>
                        <div class="layui-input-inline" style="width:190px; float: left;">
                            <select  name="parameter">
                                <c:forEach items="${dicEntity}" var="item">
                                    <option value="${item.dictValue}">${item.dictLabel}</option>
                                </c:forEach>
                            </select>
                            <span class="xing" style="margin-left: 101%;"></span>
                        </div>
                    </td>
                </tr>
                <tr style="height: 10px"></tr>
                <tr>
                    <td><label class="layui-form-label">合同数量</label></td>
                    <td>
                        <input class="layui-input" id="depreciation" name="warehousequantity" lay-verify="warehousequantity" type="number" style="width: 190px;">
                        <span class="xing" style="margin-left: 101%;"></span>
                    </td>
                    <td><label class="layui-form-label">单价</label></td>
                    <td>
                        <input class="layui-input" id="maintenance" name="parameter2" lay-verify="parameter2" type="number" style="width: 190px;">
                        <span class="xing" style="margin-left: 101%;"></span>
                    </td>

                </tr>

                <tr style="height: 20px"></tr>
                <tr align="center">
                    <td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:190px; margin-bottom: 10px">提交</button></td>
                    <td colspan="2"><button class="layui-btn layui-btn-primary" style="margin-bottom: 10px">取消</button></td>
                </tr>
            </table>
        </xblock>
    </form>
</div>

<script>

    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })

    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date1',
            value:new Date()
        });

        laydate.render({
            elem: '#date2',
            type: 'month',
            value: new Date(),
            done:function(value, date, endDate) {
                $('#dateTime').val(value);
            }
        });

        var $ = layui.jquery, active = {
            reload:function () {
                var dateTime = $('#dateTime').val()
                if (dateTime.length < 4) {
                    var time = new Date();
                    var day = ("0" + time.getDate()).slice(-2);
                    var month = ("0" + (time.getMonth() + 1)).slice(-2);
                    var today = time.getFullYear() + "-" + (month);
                    dateTime = today;
                }
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'stockId':$("#keyword1").val(),
                        'date':dateTime
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }

        table.render({
            elem: '#tableList'
            ,url: '/hydroPower/list.do' //数据接口
            ,id :'contentTable'
            ,where:{'stockId':$("#keyword1").val(),'date':$('#dateTime').val()}
            ,totalRow: true
            ,toolbar: '#toolbar'
            ,page: true //开启分页
            ,request: {   //如果无需自定义请求参数，可不加该参数
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,response: {   //如果无需自定义数据响应名称，可不加该参数
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,cols: [[ //表头

                {type: 'checkbox', fixed: 'left'},
                {field: 'warehouse', title: '仓库', totalRowText: '合计'},
                {field: 'createdate', title: '时间'},
                {field: 'supplier', title: '供应商'}
                ,{field: 'parameter', title: '名称'}
                // ,{field: 'rentalquantity', title: '租赁数量'}
                ,{field: 'warehousequantity', title: '供应商合同数量' , totalRow: true}
                ,{field: 'price', title: '单价'}
                ,{field: 'water', title: '水费：3%' , totalRow: true}
                ,{field: 'power', title: '电费：13%' , totalRow: true}
            ]]
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                })
                /*$('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式
                /!*$('th').css({'background-color': '#5792c6', 'color': '#fff','font-weight':'bold'}) 表头的样式 *!/
                $('th').hide();//表头隐藏的样式
                $('.layui-table-page').css('margin-top','40px');//页码部分的高度调整*/
            }
        });


        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $("#add").click(function(){
            $("#brand1").hide()
            $("#brand2").hide()
            layer.open({
                type: 1 ,				//Page层类型
                area: ['670px', '330px'] 	//宽  高
                ,title: '新增'
                ,shade: 0.6 			//遮罩透明度
                ,maxmin: true 			//允许全屏最小化
                ,anim: 1 				//0-6的动画形式，-1不开启
                ,content: $('#addDivID')
                ,success: function(){
                	$("input[name='warehousequantity']").val("");
                	$("input[name='parameter2']").val("");
                    form.render();
                }
            });
        });

        //批量删除
        $("#del").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            var idArr = new Array();
            if(data.length == 0){
                toastrStyle();
                toastr.warning("请至少选择一条记录！");
            } else {
                for(var i=0;i < data.length;i++){
                    idArr[i] = data[i].id;
                }
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath }/hydroPower/del.do',
                    data:{"idArr" : idArr},
                    success:function(data){
                        layer.confirm('确定删除吗？', function(){
                            if(data > 0){
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                setTimeout(function(){
                                    window.location.reload();
                                },2000);
                            }else{
                                toastr.warning("删除失败！");
                                location.reload();
                            }
                        });
                    }
                });
            }
        });

        form.verify({
            parameter3:function (value, item) {
                if(value.trim() == ''){
                    return '日期不能为空';
                }
            },
            warehousequantity:function (value, item) {
                if(value.trim() == ''){
                    return '数量不能为空';
                }
            },
            parameter2:function (value, item) {
                if(value.trim() == ''){
                    return '单价不能为空';
                }
            }
        })

        /**
         * 通用表单提交(AJAX方式)
         */
        form.on('submit(addForm)', function () {



            $("#subBtn").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath }/hydroPower/add.do',
                data:$('#addFormID').serialize(),
                cache:false,
            }).done(
                function(res) {
                    if (res > 0) {
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })

    });
    toastrStyle()

</script>
</body>

</html>
